<?php
/**
 ** added by lss@2017/07/14
 ** 设置生成第一次推荐计划
**/
set_time_limit(0);
error_reporting('ALL');
date_default_timezone_set("PRC");
include('./db_config.php');
include('./function.php');
//print_r($argv);
$type = 20; //北京赛车对应数据库中的dat_type
$algo_id = $argv[1];
$first = $argv[2];
$last = $argv[3];

if(!$algo_id || !is_numeric($algo_id))
{
	exit('参数缺失');
}

if(intval($last) - intval($first) !=2)
{
	exit('参数错误');
}

//die($algo_id.','.$first.','.$last);

//1.连接数据库->pdo方式
$db_pdo_link = pdo_write_read_link();

//3.定义计划种类
$guess_type_array = array('gjw','yjw','jjw','sjw','wjw','ljw','qjw','bjw','njw','tjw','q2zx','q3zx','gyhz','gyhzdx','gyhzds');

foreach($guess_type_array as $guess_type_single)
{
	$sql = "select guess_id,guess_type from pk10_referral_guess_new where exp_first = '{$first}' and exp_last ='{$last}' and guess_type_plan='{$algo_id}'";

	$list_15_result = $db_pdo_link->query($sql);
	
	$list_15_array = $list_15_result->fetchAll(PDO::FETCH_ASSOC);

	$final_list_15_array = array();

	if(count($list_15_array) == 0)
	{
		foreach($list_15_array as $list_k=>$list_1_single)
		{
			if(trim($list_1_single['guess_type']) == trim($guess_type_single))
			{
				$final_list_15_array [] = $list_15_array[$k];
				break;   
			}
		}
	}

	$countInfo = $final_list_15_array;

	if(count( $countInfo ) == 0 )
	{                
		if(in_array($guess_type_single,array('gjw','yjw','jjw','sjw','wjw','ljw','qjw','bjw','njw','tjw')))
		{
			//1-10的推荐为固定5位
			$codes = getRandomCode(1,10,5);
			$recom_yards = '5';
		}else if($guess_type_single == 'q2zx')
		{
			$codes = getRandomCode(1,10,7);

			$codes.='*'.getRandomCode(1,10,7);
			$recom_yards = '7';

		}else if($guess_type_single == 'q3zx')
		{
			$codes = getRandomCode(1,10,8);

			$codes.='*'.getRandomCode(1,10,8);

			$codes.='*'.getRandomCode(1,10,8);
			$recom_yards = '8';

		}else if($guess_type_single == 'gyhz')
		{
			$codes = getRandomCode(3,19,8);
			$recom_yards = '8';
		}else if($guess_type_single == 'gyhzds')
		{
			 $codes = rand('0','1');  //0为双  1为单
			 $recom_yards = '1';
		}else if($guess_type_single == 'gyhzdx')
		{
			$codes = rand('0','1');  //0为小  1为大
			$recom_yards = '1';
		}
		$time = date('Y-m-d H:i:s');
		$insert_sql = "insert into `pk10_referral_guess_new`(exp_first,exp_last,dat_codes,guess_type,guess_type_plan,recom_yards,addtime) values('{$first}','{$last}','{$codes}','{$guess_type_single}','{$algo_id}','{$recom_yards}','{$time}')";
		
		//echo $insert_sql;

		$db_pdo_link->exec($insert_sql);
		
		$recom_yards = '';
	}
}
?>
